<template>
    <ul class="slide-tab">
        <li v-for="(item, index) in slideTabs"
            class="slide-tab-item"
            :class="[index === currentIndex ? 'slide-tab-item-active' : '']"
            @mouseover="tabOver(index)">
            {{item}}
        </li>
    </ul>
</template>

<style lang="less">
    .slide-tab {
        width: 60px;
        height: 300px;
        color: #fff;
        font-size: 14px;
        background-color: #222;
        padding: 7px 0;

        &-item {
            position: relative;
            cursor: pointer;
            text-align: center;
            line-height: 36px;
            margin-bottom: 14px;

            &:hover, &-active {
                background: #ED4040;
                background: rgba(237, 64, 64, .8);
                z-index: 11;

                &:before {
                    content: '';
                    position: absolute;
                    top: 12px;
                    left: -6px;
                    width: 0;
                    height: 0;
                    border-top: 6px solid transparent;
                    border-right: 6px solid #ED4040;
                    border-right: 6px solid rgba(237, 64, 64, .8);
                    border-bottom: 6px solid transparent;
                }
            }
        }
    }
</style>

<script>
  import eventBus from 'byted-toutiao-pc-business-components/src/js/eventBus.js'

  export default {
    name: 'SlideList',
    props: {
      slideList: {
        type: Array,
        default: []
      }
    },
    data () {
      return {
        slideTabs: ['要闻', '社会', '娱乐', '体育', '军事', '明星'],
        currentIndex: 0
      }
    },
    mounted () {
      eventBus.$on('slide-list-change', (index) => {
        if (this.currentIndex !== index) {
          this.currentIndex = index
        }
      })
    },
    methods: {
      tabOver (index) {
        if (this.currentIndex !== index) {
          this.currentIndex = index
          eventBus.$emit('slide-tab-change', index)
          window.ttAnalysis && window.ttAnalysis.send('event', {
            ev: 'focus_tab_hover'
          })
        }
      }
    }
  }
</script>



// WEBPACK FOOTER //
// slide-tab.vue?be86dec0